package com.kuaidian.pojo;

import java.sql.Clob;

import org.springframework.util.FileCopyUtils;
/**
 * 
 * @author zhaoshuaishuai
 *
 */
public class LowerCaseRow extends Row {

	private static final long serialVersionUID = 1L;

	public Object put(Object name, Object value) {
		// 如果key是String就小写他们
		if (name.getClass().equals(String.class)) {
			name = ((String) name).toLowerCase();
		}
		// 如果value是clob就变成String
		if (null != value && Clob.class.isAssignableFrom(value.getClass())) {
			Clob c = (Clob) value;
			try {
				value = FileCopyUtils.copyToString(c.getCharacterStream());
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		if (!containsKey(name)) {
			ordering.add(name); // 将键保存起来
		}
		super.put(name, value);
		if (functionMap != null && functionMap.containsKey(name))
			functionMap.remove(name);
		return value;
	}

	public int getInt(int which, int defaultValue) {
		Object key = ordering.get(which);
		if (key.getClass().isAssignableFrom(String.class)) {
			key = ((String) key).toLowerCase();
		}
		return getInt(key, defaultValue);
	}
}
